﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using E_Commerce.Domain.Interfaces;
using Dapper;
using Microsoft.Extensions.Configuration;
using E_Commerce.Domain.Entities;

/// <summary>
/// 实现类
/// </summary>
namespace E_Commerce.Infrastructure.Data
{
    public class UserRepository:DapperRepository<Users>,IUserRepository
    {
        //依赖注入
        public IConfiguration _configuration;

        public UserRepository(IConfiguration configuration)
        {
           this._configuration = configuration;
            //连接字符串
            this.ConnStr = _configuration.GetConnectionString("ConnStr");
            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
            Conn = new MySql.Data.MySqlClient.MySqlConnection(this.ConnStr);
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="LoginName">用户名</param>
        /// <param name="LoginPwd">密码</param>
        /// <returns></returns>
        public int LoginAsync(string LoginName, string LoginPwd)
        {
            string sql = $"SELECT * from Users where LoginName='{LoginName}' && LoginPwd='{LoginPwd}'";
            return Conn.Query<int>(sql).FirstOrDefault();
        }

        //重写基类的方法(多表联查)
        //public override IEnumerable<Class1> GetList(string whereCondition = "", object paras = null)
        //{

        //    return base.GetList(whereCondition, paras);
        //}
    }
}
